package com.ms.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ms.domain.entity.Album;
import com.ms.domain.entity.Music;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface AlbumMapper extends BaseMapper<Album> {

    // 查询专辑及其包含的音乐
    @Select("SELECT a.*, m.* FROM album a " +
            "LEFT JOIN music m ON a.id = m.album_id " +
            "WHERE a.id = #{albumId}")
    @Results({
            @Result(property = "id", column = "id"),
            @Result(property = "musicList", javaType = List.class,
                    column = "id", many = @Many(select = "selectMusicByAlbumId"))
    })
    Album selectAlbumWithMusic(@Param("albumId") Integer albumId);

    @Select("SELECT * FROM music WHERE album_id = #{albumId}")
    List<Music> selectMusicByAlbumId(@Param("albumId") Integer albumId);
}
